Skip to content

use typed quantize config instead of a raw dict#1249

Merged
shengliangxu merged 5 commits intomainfrom
shengliangx/use-typed-config
Apr 14, 2026
Merged

use typed quantize config instead of a raw dict#1249
shengliangxu merged 5 commits intomainfrom
shengliangx/use-typed-config

Conversation

@shengliangxu
Copy link
Copy Markdown
Collaborator

@shengliangxu shengliangxu commented Apr 13, 2026

What does this PR do?

But fix:

Use typed QuantizeConfig instead using raw dict for formal typed ModelOpt configs.

The dict typing was accidental.

Summary by CodeRabbit

  • Refactor

    • Quantization recipe configuration is now implemented with a strongly-typed, structured schema that enforces type safety and provides enhanced validation with comprehensive error detection capabilities.
  • Tests

    • Updated recipe loading tests to correctly validate quantization configurations when recipes are loaded from directories, fully supporting the new structured object-based configuration format.

Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Apr 13, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7acba763-eadf-4201-b38d-8cdba8b2a851

📥 Commits

Reviewing files that changed from the base of the PR and between 14b78ae and 7671387.

📒 Files selected for processing (3)
  • examples/llm_ptq/hf_ptq.py
  • modelopt/recipe/config.py
  • tests/unit/recipe/test_loader.py

📝 Walkthrough

Walkthrough

The changes introduce type safety to the quantization configuration by replacing an untyped dictionary with a strongly typed QuantizeConfig object in the PTQ recipe configuration. Related code and tests are updated to work with the structured type instead of plain dictionaries.

Changes

Cohort / File(s) Summary
Config Type Strengthening
modelopt/recipe/config.py
The quantize field in ModelOptPTQRecipe changes from dict[str, Any] with default {} to QuantizeConfig with instantiated default QuantizeConfig(). Adds import of QuantizeConfig and removes unused Any import.
Usage Update
examples/llm_ptq/hf_ptq.py
Calls .model_dump() on the recipe.quantize object to convert it to a plain dictionary representation when assigning to quant_cfg for downstream quantization logic.
Test Updates
tests/unit/recipe/test_loader.py
Adjusts assertions in test_load_recipe_dir to access recipe.quantize properties as object attributes (recipe.quantize.algorithm, recipe.quantize.quant_cfg) rather than dictionary keys.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: replacing an untyped dict for quantize configuration with a formally typed QuantizeConfig object.
Security Anti-Patterns ✅ Passed All three modified files contain no security anti-patterns from SECURITY.md including unsafe deserialization, hardcoded remote code execution flags, dynamic code execution, or security bypass comments.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch shengliangx/use-typed-config

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-04-14 01:25 UTC

safe from Pydantic v2

Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
@shengliangxu shengliangxu marked this pull request as ready for review April 13, 2026 20:59
@shengliangxu shengliangxu requested a review from a team as a code owner April 13, 2026 20:59
@shengliangxu shengliangxu requested a review from Edwardf0t1 April 13, 2026 20:59
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.44%. Comparing base (202c3d3) to head (d5d179a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1249      +/-   ##
==========================================
+ Coverage   76.90%   77.44%   +0.54%     
==========================================
  Files         350      350              
  Lines       40524    40524              
==========================================
+ Hits        31166    31385     +219     
+ Misses       9358     9139     -219     
Flag Coverage Δ
examples 43.80% <100.00%> (+1.17%) ⬆️
gpu 57.43% <100.00%> (-0.11%) ⬇️
unit 55.61% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@cjluo-nv cjluo-nv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small, well-scoped bug fix (6 lines changed across 3 files). Changes ModelOptPTQRecipe.quantize from dict[str, Any] to the proper typed QuantizeConfig, fixing an accidental raw-dict typing. The hf_ptq.py example correctly calls .model_dump() to convert back to a dict where downstream code expects dict operations (.append(), copy.deepcopy(), subscript access). Tests are updated to match the new typed access pattern. The change is correct and straightforward.

@shengliangxu shengliangxu merged commit b6c6ec3 into main Apr 14, 2026
44 checks passed
@shengliangxu shengliangxu deleted the shengliangx/use-typed-config branch April 14, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants